package com.zm.zb100.repository;

import com.zm.zb100.persistence.entity.db.EpsCommodityAttractDesign;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.Date;
import java.util.List;
import java.util.Optional;

/**
 * @author chuanbai
 * @date 2024/3/28 0:15
 * @deception
 */
@Repository
public interface EpsCommodityAttractDesignRepository extends JpaRepository<EpsCommodityAttractDesign, Long> {

    /**
     * 根据渠道查商品引流款集合
     */
    @Query("select e from EpsCommodityAttractDesign e")
    List<EpsCommodityAttractDesign> findEpsCommodityAttractDesignByChannel(@Param("epsChannelName") String epsChannelName);

    /**
     * 修改引流款集合
     */
    @Modifying
    @Query("UPDATE EpsCommodityAttractDesign d SET d.designNo = :newDesignNo, d.modifierId = :modifierId, d.modifierName = :modifierName, d.modifyTime = :modifyTime " +
            "WHERE d.designNo = :designNo " +
            "and d.epsChannelName = :epsChannelName")
    Integer updateEpsCommodityAttractDesign(
                                         @Param("modifierId") Long modifierId,
                                         @Param("modifierName") String modifierName,
                                         @Param("modifyTime") Date modifyTime,
                                         @Param("designNo") String designNo,
                                         @Param("newDesignNo") String newDesignNo,
                                         @Param("epsChannelName") String epsChannelName);

    @Modifying
    @Query("delete from EpsCommodityAttractDesign where designNo = :designNo" +
            " and epsChannelName = :epsChannelName")
    Integer deleteList(
            @Param("designNo") String designNo,
            @Param("epsChannelName") String epsChannelName
    );

}
